﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Net;
using System;
using System.Collections.Generic;
using System.Text;

namespace Momentum.Types
{
    public class mBox : mObject
    {

        #region Initialization


        public mBox()
            : base()
        {
            this.Type = Momentum.Static.mStaticObject.Types.Box;
        }

        public mBox(mBox other)
            : base()
        {
            this.Type = Momentum.Static.mStaticObject.Types.Box;
            this.CollisionRadius = other.CollisionRadius;
            this.Mass = other.Mass;
            this.ObjectScale = other.ObjectScale;
            this.ShadowOffset = other.ShadowOffset;
            this.TotalHP = other.TotalHP;
            this.Name = other.Name;
        }

        public void Load(ContentManager content)
        {
            m_ObjectTexture = content.Load<Texture2D>("Objects/" + m_Name + "Texture");
            m_ObjectShadowTexture = content.Load<Texture2D>("Objects/" + m_Name + "ShadowTexture");
        }


        #endregion

    }

    #region Content Reader and Writer


    public class mBoxContentReader : ContentTypeReader<mBox>
    {
        protected override mBox Read(ContentReader input, mBox existingInstance)
        {
            mBox box = new mBox();
            box.Name = input.ReadString();
            box.CollisionRadius = input.ReadInt32();
            box.Mass = input.ReadInt32();
            box.ObjectScale = (float)input.ReadSingle();
            box.ShadowOffset = input.ReadVector2();
            box.TotalHP = input.ReadInt32();
            return box;
        }
    }

    [ContentTypeWriter]
    public class mBoxContentWriter : ContentTypeWriter<mBox>
    {
        protected override void Write(ContentWriter output, mBox box)
        {
            output.Write(box.Name);
            output.Write(box.CollisionRadius);
            output.Write(box.Mass);
            output.Write(box.ObjectScale);
            output.Write(box.ShadowOffset);
            output.Write(box.TotalHP);
        }
        public override string GetRuntimeReader(TargetPlatform targetPlatform)
        {
            return typeof(mBoxContentReader).AssemblyQualifiedName;
        }
    }


    #endregion
}
